Pedro Pascal speedrun

There is this new Zig book published recently by Pedro Duarte Faria. It is very enjoyable! I have not read it thoroughly yet, but it revisited many of the pain points I had when learning Zig with great clarity.

Since I am familiar with the language already, I tried to speedrun chapter 15 where we create a greyscale image filter, just to see where I am at. The exercise is fairly well-described, so I tried my best to follow the reference implementation as little as possible.

Turns out it was not the best “pure Zig” test: PNG is a non-trivial file format, the book recommends the C libspng library to handle image decoding and manipulation. So, instead of time-testing my Zig skills, I found myself wandering through libspng docs, and looking frequently to the reference solution and the other chapters of the book. I learned a lot on how to properly interface with C from Zig—it’s @ptrCast.

It took me 53 min 15s while blasting Bicep to obtained my own greyscale Pedro Pascal:

Is it fast, is it slow? I am just happy: I felt unencumbered, and I learned concepts tangent to my previous knowledge effortlessly. I carried the bliss of it during the rest of the day.

Code is at ~lvig/pedro just as it was when I stopped the clock. I’ll make a polished CLI version later as an additional exercise.